package leetcodecompetition.D349;

import java.util.Arrays;

/**
 * @Author: Siantar
 * @Date: 2023-06-11-11:13
 * @Description: 1.0
 */
public class T6449 {
    public long minCost(int[] nums, int x) {
        int n = nums.length;
        int[] val = new int[n];
        Arrays.fill(val,Integer.MAX_VALUE);
        long res = Long.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            long sum=(long)i*x;
            for (int j = 0; j < n; j++) {
                val[j]=Math.min(val[j],nums[(j+i)%n]);
                sum+=val[j];
            }
            res=Math.min(res,sum);
        }
        return res;
    }
}
